<?php
session_start();
if (empty($_SESSION['admin_email'])) {
    echo '尚未登录，请先登录 <a href="index.php?c=login">登录</a>';
    exit();
}

// 获取到管理员数据
$adminName = $_POST['admin_name'];
$adminEmail = $_POST['admin_email'];
$adminPassword = $_POST['admin_password'];
$adminPassword2 = $_POST['admin_password2'];

if (mb_strlen($adminName) < 2 || mb_strlen($adminName) > 50) {
    echo '姓名限制2~50个字';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
// 10~100
if (mb_strlen($adminEmail) < 1 || mb_strlen($adminEmail) > 100) {
    echo '邮箱限制1~100个字';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
// 10~8000
if (mb_strlen($adminPassword) < 6 || mb_strlen($adminPassword) > 20) {
    echo '密码长度6~20。';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
if ($adminPassword !== $adminPassword2) {
    echo '两次密码输入不一致。';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}

include_once APP_PATH . "./model/admin_add_save.php";

if ($result) {
    echo "插入成功。<a href='index.php?c=admin_list'>返回列表页</a>";
    exit();
} else {
    echo "插入失败，错误信息：" . $db->errorInfo()[2] . "，请联系管理员：303410541@qq.com";
}

